package com.ssy.lingxi.member.merchant.controller.web;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.AuthTreeGetButtonVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.AuthTreeMenuButtonCheckIdVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.*;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.*;
import com.ssy.lingxi.member.merchant.service.web.IMemberAbilityRoleService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @menu 系统能力-权限管理-角色管理
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-30
 */
@RestController
@RequestMapping("/member/role")
public class MemberAbilityRoleController {
    @Resource
    private IMemberAbilityRoleService memberAbilityRoleService;

    /**
     * 分页、模糊查询会员角色
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberRoleQueryVO>> pageMemberRole(@RequestHeader HttpHeaders headers, @Valid MemberRolePageVO pageVO) {
        return memberAbilityRoleService.pageMemberRole(headers, pageVO);
    }

    /**
     * 根据名称，分页、模糊查询会员角色
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/page/byname", method = RequestMethod.GET)
    Wrapper<PageData<MemberRoleQueryVO>> pageMemberRoleByName(@RequestHeader HttpHeaders headers, @Valid MemberRolePageByNameVO pageVO) {
        return memberAbilityRoleService.pageMemberRoleByName(headers, pageVO);
    }

    /**
     * 获取左侧权限菜单、组织机构列表
     * @param headers HttpHeaders信息
     * @return 查询结果
     */
    @RequestMapping(value = "/auth/tree", method = RequestMethod.GET)
    public Wrapper<MemberAbilityRoleAuthConfigVO> treeMemberAuth(@RequestHeader HttpHeaders headers, @Valid MemberRoleIdVO idVO) {
        return memberAbilityRoleService.treeMemberAuth(headers, idVO);
    }

    /**
     * 根据左侧菜单Id，查询右侧按钮列表、菜单是否可配置数据权限
     * @param headers HttpHeaders信息
     * @param buttonVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/auth/button", method = RequestMethod.GET)
    public Wrapper<MemberAbilityRoleAuthButtonVO> getMemberAuthButtons(@RequestHeader HttpHeaders headers, @Valid AuthTreeGetButtonVO buttonVO) {
        return memberAbilityRoleService.getMemberAuthButtons(headers, buttonVO);
    }

    /**
     * 新增会员角色
     * @param headers HttpHeaders信息
     * @param addVO 接口参数
     * @return 新增结果
     */
    @RequestMapping("/add")
    public Wrapper<Void> addMemberRole(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberAbilityRoleAddVO addVO) {
        return memberAbilityRoleService.addMemberRole(headers, addVO);
    }

    /**
     * 查询单个会员角色的信息
     * @param headers HttpHeaders信息
     * @param idVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public Wrapper<MemberRoleGetVO> getMemberRoleAuth(@RequestHeader HttpHeaders headers, @Valid MemberRoleIdVO idVO) {
        return memberAbilityRoleService.getMemberRole(headers, idVO);
    }

    /**
     * 查询左侧树形权限菜单中勾选的Id列表
     * @param headers HttpHeaders信息
     * @param idVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/auth/tree/check", method = RequestMethod.GET)
    public Wrapper<AuthTreeMenuButtonCheckIdVO> getTreeCheckIds(@RequestHeader HttpHeaders headers, @Valid MemberRoleIdVO idVO) {
        return memberAbilityRoleService.getTreeCheckIds(headers, idVO);
    }

    /**
     * 点击左侧菜单，查询右侧勾选的按钮Id列表、数据权限配置
     * @param headers HttpHeaders信息
     * @param buttonVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/auth/button/check", method = RequestMethod.GET)
    public Wrapper<MemberAbilityRoleGetAuthVO> getButtonCheckIds(@RequestHeader HttpHeaders headers, MemberRoleButtonVO buttonVO) {
        return memberAbilityRoleService.getButtonCheckIds(headers, buttonVO);
    }

    /**
     * 修改会员角色及菜单权限、数据权限
     * @param headers HttpHeaders信息
     * @param updateVO 接口参数
     * @return 更新结果
     */
    @RequestMapping("/update")
    public Wrapper<Void> updateMemberRole(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberAbilityRoleUpdateVO updateVO) {
        return memberAbilityRoleService.updateMemberRole(headers, updateVO);
    }

    /**
     * 新增或更新会员角色菜单关联按钮
     * @param headers HttpHeaders信息
     * @param upsertVO 接口参数
     * @return 新增或更新结果
     */
    @RequestMapping("/button/upsert")
    public Wrapper<Void> updateMemberRoleButton(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberRoleUpdateButtonVO upsertVO) {
        return memberAbilityRoleService.updateMemberRoleButton(headers, upsertVO);
    }

    /**
     * 删除会员角色
     * @param headers HttpHeaders信息
     * @param idVO 接口参数
     * @return 删除结果
     */
    @RequestMapping("/delete")
    public Wrapper<Void> deleteMemberRole(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberRoleIdVO idVO) {
        return memberAbilityRoleService.deleteMemberRole(headers, idVO);
    }

    /**
     * 更新会员角色状态
     * @param headers HttpHeaders信息
     * @param statusVO 接口参数
     * @return 更新结果
     */
    @RequestMapping("/updatestatus")
    public Wrapper<Void> updateMemberRoleStatus(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberRoleUpdateStatusVO statusVO) {
        return memberAbilityRoleService.updateMemberRoleStatus(headers, statusVO);
    }
}
